﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;


namespace SindSaudeCamadas.Dados
{
    public class acordos
    {
            Conex conexao = new Conex();
            public DataTable carregaAcordos()
            {
                DataTable dt = new DataTable();
                MySqlCommand cmdSQL = new MySqlCommand();
                MySqlDataAdapter daSQL = new MySqlDataAdapter();
                try
                {
                    string conex = ConfigurationManager.AppSettings["SindSaude"].ToString();
                    cmdSQL.Connection = conexao.retornaConexao(conex);

                    cmdSQL.CommandType = CommandType.Text;
                    cmdSQL.CommandType = CommandType.Text;
                    cmdSQL.CommandText = "select * from tbacordos;";

                    cmdSQL.Connection.Open();
                    daSQL.SelectCommand = cmdSQL;
                    daSQL.Fill(dt);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    cmdSQL.Connection.Dispose();
                    cmdSQL.Dispose();
                    daSQL.Dispose();
                }
                return dt;
            }
            public bool insereAcordos(string strCaminho, string strNome,int intAno)
            {
                bool insere = false;
                DataTable dt = new DataTable();
                MySqlCommand cmdSQL = new MySqlCommand();
                try
                {
                    string conex = ConfigurationManager.AppSettings["SindSaude"].ToString();
                    cmdSQL.Connection = conexao.retornaConexao(conex);

                    cmdSQL.CommandType = CommandType.Text;
                    cmdSQL.CommandText = "insert into tbacordos(strCaminho,strNome,datArquivo,intStatu,Ano)values(@strCaminho,@strNome,now(),0,@Ano);";
                    cmdSQL.Parameters.AddWithValue("@strCaminho", strCaminho);
                    cmdSQL.Parameters.AddWithValue("@strNome", strNome);
                    cmdSQL.Parameters.AddWithValue("@Ano", intAno);
                    cmdSQL.Connection.Open();
                    cmdSQL.ExecuteNonQuery();
                    insere = true;
                }
                catch (Exception)
                {
                    insere = false;
                }
                finally
                {
                    cmdSQL.Connection.Dispose();
                    cmdSQL.Dispose();
                }
                return insere;
            }
    }
}
